/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#include "ChrFaceHairStylDbc.h"

#include "GNativeFile.h"

namespace GNgine
{
	const std::string ChrFaceHairStylDbc::PATH="dbc/CharacterFacialHairStyles.dbc";

	ChrFaceHairStylDbc::ChrFaceHairStylDbc()
	{
		GFile* file=new GNativeFile(PATH);
		_dbc=new WOWDbcFile(file);
		delete file;
		assert(_dbc);
	}

	ChrFaceHairStylDbc& ChrFaceHairStylDbc::getSingleton()
	{
		static ChrFaceHairStylDbc inst;
		return inst;
	}

	int ChrFaceHairStylDbc::getRecordCount(Ogre::uint race, Ogre::uint gender)
	{
		if(!_dbc){
			return 0;
		}
		int n=0;
		int cnt=_dbc->getRecordCount();
		for(int i=0;i<cnt;i++){
			unsigned int recordRace=_dbc->getUIntField(i,0);
			unsigned int recordGender=_dbc->getUIntField(i,1);
			if(race==recordRace&&gender==recordGender){
				n++;
			}
		}
		return n;
	}

	CharFaceHairRecord *ChrFaceHairStylDbc::getRecord(Ogre::uint race,Ogre::uint gender,Ogre::uint hairstyle)
	{
		if(!_dbc){
			return 0;
		}
		int cnt=_dbc->getRecordCount();
		for(int i=0;i<cnt;i++){
			unsigned int recordRace=_dbc->getUIntField(i,0);
			unsigned int recordGender=_dbc->getUIntField(i,1);
			unsigned int recordStyle=_dbc->getUIntField(i,2);
		
			if(race==recordRace&&gender==recordGender&&hairstyle==recordStyle){
				CharFaceHairRecord *record=(CharFaceHairRecord*)_dbc->getRecordData(i);
				return record;
			}
		}
		return 0;
	}
	
}

